package com.sh.data.engine.application.model.request.management;

import com.sh.data.engine.common.annotation.EnumValue;
import com.sh.data.engine.common.annotation.crypto.EncryptField;
import com.sh.data.engine.common.enumDefinition.DSType;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;


/**
 * @author: mengzheng.mhc
 * @date: 2024/6/24 11:31
 */
@Data
@Schema
public class StorageSaveRequest {

    /**
     * 存储id
     */
    @Schema(description = "存储id", hidden = true)
    private Long storageId;

    /**
     * 名称
     */
//    @NotBlank(message = "存储名称不能为空")
//    @Length(min = 2, max = 32, message = "数据源名称长度在2-32个字符")
//    @Pattern(regexp = "[a-zA-Z0-9_\\u4e00-\\u9fa5]+", message = "数据源名称支持中文、字母、数字和下划线")
//    @Schema(description = "存储名")
//    private String storageName;

    /**
     * 数据源类型
     */
    @NotBlank(message = "存储类型不能为空")
    @EnumValue(enumClass = DSType.class, enumMethod = "isValidDSType", message = "数据源类型值不匹配")
    @Schema(description = "存储类型，目前支持Hive，PostgreSQL, TiDB, SAP", requiredMode = RequiredMode.REQUIRED)
    private String storageType;

    /**
     * 链接地址
     */
    @Schema(description = "链接地址", requiredMode = RequiredMode.REQUIRED)
    private String storageLink;

    /**
     * 描述
     */
//    @Length(max = 128, message = "描述不要超过128个字符")
//    @Schema(description = "存储的描述", hidden = true)
//    private String storageDesc;

    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空")
    @Schema(description = "用户名", requiredMode = RequiredMode.REQUIRED)
    private String username;

    /**
     * 密码
     */
    @NotBlank(message = "密码不能为空")
    @Schema(description = "密码", requiredMode = RequiredMode.REQUIRED)
    @EncryptField
    private String password;

    @NotBlank(message = "服务器不能为空")
    @Schema(description = "服务器", requiredMode = RequiredMode.REQUIRED)
    private String server;

    @NotNull(message = "端口不能为空")
    @Min(value = 0, message = "端口不能小于0")
    @Max(value = 65535, message = "端口不能大于65535")
    @Schema(description = "端口号", requiredMode = RequiredMode.REQUIRED)
    private Integer port;

    @Schema(description = "数据库名", requiredMode = RequiredMode.REQUIRED)
    private String dbName;

    @Schema(description = "连接属性")
    private String connectionProperty;

    @Schema(description = "pg的schema,仅存储类型为PostgreSQL时使用")
    private String schema;

    @Schema(description = "hive-site.xml的文件上传位置,仅存储类型为Hive时使用")
    private String hiveSiteAddress;

    @Schema(description = "hive-site.xml文件的原始名,仅存储类型为Hive时使用")
    private String originalFilename;
}
